<?php
namespace Biz\model\activity;

use Doraemon\pockets\datebase\BaseDbModel;

class FlashSubscribe extends BaseDbModel
{
	const _CONFIG_FILE_ = 'db_shop';

	const _CONFIG_SELECT_ = 'db_activity';

	const _DATABASE_ = 'shop_activity';

	const _TABLE_NAME = 'flash_subscribe';


	const PUSH_YES = 1;
	const PUSH_NO = 0;

	const STATUS_NORMAL = 1;
	const STATUS_DELECT = 0;

	public static function saveData($flashId, $goodsId, $uid)
	{
		$info = self::get('*', [
			'flash_id' => $flashId,
			'goods_id' => $goodsId,
			'uid' => $uid
		]);
		if ($info) {
			if ($info['status'] == self::STATUS_DELECT) {
				self::update(['status' => self::STATUS_NORMAL], [
					'id' => $info['id']
				]);
			} else if ($info['status'] == self::STATUS_NORMAL) {
				return true;
			}
		} else {
			self::insert([
				'flash_id' => $flashId,
				'goods_id' => $goodsId,
				'uid' => $uid,
				'status' => self::STATUS_NORMAL
			]);
		}
	}

	public static function InfosGrpByUid($flashId, $goodsIds) {
		$infos = self::selectInfos($flashId, $goodsIds);
		$resutls = [];
		foreach ($infos as $info) {
			$resutls[$info['uid']][$info['goods_id']] = $info;
		}
		return $resutls;

	}


	public static function selectInfos($flashId, $goodsIds) {
		return self::select('*', [
			'flash_id' => $flashId,
			'goods_id' => $goodsIds,
			'status' => self::STATUS_NORMAL
		]);
	}
}